#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @File : add_member_page.py
# @Autor: FY
# @Date: 2021/8/30
from selenium.webdriver.common.by import By

from pages.base_page import BasePage
from pages.contact_page import ContactPage


class AddMemberPage(BasePage):
    '''
    添加成员信息页面
    '''
    _base_url = r"https://work.weixin.qq.com/wework_admin/frame#contacts"

    def add_member(self, urername, acctid, phone):
        '''
        添加成员，并点击保存按钮，保存成功，跳转到 通讯录页面
        :return ContactPage:
        '''
        self.add_text(By.ID, "username", urername)
        self.add_text(By.ID, "memberAdd_acctid", acctid)
        self.add_text(By.ID, "memberAdd_phone", phone)
        self.click_element(By.XPATH, "//a[text()='保存']")
        return ContactPage(self.driver)

    def add_member_failed(self, urername, acctid, phone):
        '''
        添加成员，并点击保存按钮，保存失败
        :return  texts:
        '''
        self.add_text(By.ID, "username", urername)
        self.add_text(By.ID, "memberAdd_acctid", acctid)
        self.add_text(By.ID, "memberAdd_phone", phone)
        self.click_element(By.XPATH, "//a[text()='保存']")
        eles = self.find_elements(By.CLASS_NAME, "ww_inputWithTips_tips")
        texts = []
        for ele in eles:
            if ele.text != '':
                texts.append(ele.text)

        return texts
        # return AddMemberPage(self.driver)
